package com.csun.cmny.provider.service.impl;

import com.csun.cmny.core.support.BaseService;
import com.csun.cmny.provider.dao.DmcCsunSleepThresholdMapper;
import com.csun.cmny.provider.model.domain.DmcCsunSleepThreshold;
import com.csun.cmny.provider.service.DmcCsunSleepThresholdService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Slf4j
@Service
@Transactional
public class DmcCsunSleepThresholdServiceImpl extends BaseService<DmcCsunSleepThreshold> implements DmcCsunSleepThresholdService {
    @Resource
    private DmcCsunSleepThresholdMapper dmcCsunSleepThresholdMapper;

    @Override
    public int saveOrUpdate(DmcCsunSleepThreshold csunSleepThreshold) {

        DmcCsunSleepThreshold threshold = dmcCsunSleepThresholdMapper.selectByPrimaryKey(csunSleepThreshold.getDeviceId());
        if(threshold == null){
            return dmcCsunSleepThresholdMapper.insertSelective(csunSleepThreshold);
        }else{
            return dmcCsunSleepThresholdMapper.updateByPrimaryKeySelective(csunSleepThreshold);
        }
    }
}
